<?php // check for the user session 

            /*  if(!isset($_SESSION['email'])){
				  
				  header('Location: index.php'); }*/
?>
                  
<?php
session_start();

// Passkey that got from link
$passkey=$_GET['a'];

$tbl_name1="temp_user";

include('logic/config.php');

// Create Mysqli object
$db = new mysqli($db_server,$db_user,$db_pass,$db_database);

// Create statement object
$stmt = $db->stmt_init();

// Create a prepared statement
if($stmt->prepare("SELECT email FROM $tbl_name1 WHERE confirm_code =?")) 
{
 
   
   // Bind your variable to replace the ?
    $stmt->bind_param('s', $passkey);
 
  
    // Execute query
    $stmt->execute();
	
	$email="";
	 // Bind your result columns to variables
    $stmt->bind_result($email);
	
	$stmt->fetch();
	
	$_SESSION['email'] = $email;

		
	if($email!="")
		{
			// Close statement object
		$stmt->close();
		
		// remove the password reset query related to this user from the table
		
		
		
		// Create statement object
		$stmt = $db->stmt_init();
		
		$tbl_table = "temp_user";
		
		// Create a prepared statement
		if($stmt->prepare("Delete from $tbl_table where email='$email'")) {
		 
		 $stmt->execute();
		 
		 // Close statement object
		$stmt->close();
		
		}
?>



<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title></title>
	<meta name="description" content="">
	<meta name="author" content="">

	<meta name="viewport" content="width=device-width">

	<link rel="stylesheet" href="css/bootstrap.min.css">
	<style>
	body {
	  padding-top: 60px;
	  padding-bottom: 40px;
	}
	</style>
	<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
	<link rel="stylesheet" href="css/style.css">
	<script type="text/javascript" src="js/libs/jquery-1.7.2.min.js"></script>
	<script src="js/libs/modernizr-2.5.3-respond-1.1.0.min.js"></script>
</head>
<body>
<!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="index.php">E-library</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li><a href="index.php">Home</a></li>

				  <li><a href="register.php">Register</a></li>
				  <li><a href="login.php">Log In</a></li>
			 
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container">

      <!-- Main hero unit for a primary marketing message or call to action -->
      <div class="small-box">
        
        
        	
            
            <form method="POST" id="reset_password_form" class="well form-center" action="change-password-on-reset.php" style="width:300px;margin:0 auto 20px auto!important;">
            
            <h1>Password Reset</h1><hr>
            
			<p>Please enter the new password for your E-library Account.</p>
            <label for="reset_password" >New Password </label><input type="password" id="reset_password" name="reset_password" >
            <label for="c_reset_password" >Confirm Password </label><input type="password" id="c_reset_password" name="c_reset_password" >
           
           <p> 
          	 <input type="submit" id="reset_submit" class="btn btn-primary btn-large" value="Save" >
           </p>
            
            </form>
            
             <div id="pass_error">
   			 </div>
        	
        
      </div>

     

      <hr>

      <footer>
        <p>&copy; Company 2012</p>
      </footer>

	

    </div> <!-- /container -->
    
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>-->

<script type="text/javascript">


// ajax code for password reset form
$("#reset_submit").click(function(){

  password1=$("#reset_password").val();
  password2=$("#c_reset_password").val();
  email_error = $("#pass_error"); 
  form = $("#reset_password_form");
  $.ajax({
   type: "POST",
   url: "logic/change-password-on-reset.php",
   data: "password="+password1+"&c_password="+password2,
   success: function(html){
	
	if(html==='blank_password' || html==='short_password')
	{
		 email_error.html("<div class='alert alert-error'>Passwords should be atleast 6 characters long.</div>");
		} 
	
	   
    else if(html==='miss_match')
    {
     email_error.html("<div class='alert alert-error'>Passwords did not match. Check again.</div>");
    }
	else if(html==='true')
    {
		$("#reset_password_form").hide();
     email_error.html("<div class='alert alert-success'>Password changed successfully. Now you can login with your new password.</div>");
	 form.hide(1500);
	 
    }
	else 
	{
		 email_error.html("<div class='alert alert-error'>Something went wrong. Please try again </div>");
		}
	
	
   },
   beforeSend:function()
   {
   email_error.html('<img src="img/ajax-loader.gif">')
   }
  });
  return false;
 });



</script>


</body>
</html>



<?php	
		
			}
			
			// if not found passkey, display message "Wrong Confirmation code"
		else 
		{
		
?>

<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title></title>
	<meta name="description" content="">
	<meta name="author" content="">

	<meta name="viewport" content="width=device-width">

	<link rel="stylesheet" href="css/bootstrap.min.css">
	<style>
	body {
	  padding-top: 60px;
	  padding-bottom: 40px;
	}
	</style>
	<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
	<link rel="stylesheet" href="css/style.css">
	<script type="text/javascript" src="js/libs/jquery-1.7.2.min.js"></script>
	<script src="js/libs/modernizr-2.5.3-respond-1.1.0.min.js"></script>
</head>
<body>
<!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="index.php">E-library</a>
          <div class="nav-collapse">
            <ul class="nav">
              <li><a href="index.php">Home</a></li>

				  <li><a href="register.php">Register</a></li>
				  <li><a href="#">Log In</a></li>
			 
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container">

      <!-- Main hero unit for a primary marketing message or call to action -->
      <div class="hero-unit">
        <h3>Your Password Reset link expired. Try again</h3><br>
        
        	
        	
        
      </div>

     

      <hr>

      <footer>
        <p>&copy; Company 2012</p>
      </footer>

	

    </div> <!-- /container -->


</body>
</html>

<?php
		}
		
		
}
?>